<?php
namespace app\passenger\controller;
use app\AdminRest;
use think\App;
use app\passenger\model\Coupon as Model;
use app\passenger\model\AdminCompany;
use app\passenger\model\AdminActive;
use app\passenger\model\Log;
use think\facade\Cache;
use think\facade\Db;


class AdminCoupon extends AdminRest
{

    protected $model;

    protected $log_model;

    protected $active_model;

    public function __construct(App $app) {
        parent::__construct($app);

        $this->model        = new Model();

        $this->log_model    = new Log();

        $this->active_model = new AdminActive();
        //修改过期状态
        $this->model->changeStatus();
    }

    /**
     * User: chenniang
     * Date: 2019-12-18 14:30
     * @return void
     * descrption:列表
     */
    public function couponList(){
       $input = $this->_input;
        //uniacid
       $dis[] = ['a.uniacid','=',$this->_uniacid];
        //类型
       if(!empty($input['type'])){

           $dis[] = ['a.type','=',$input['type']];
       }
       //状态
       if(!empty($input['status'])){

           $dis[] = ['a.status','=',$input['status']];
       }
        //用户名称
       if(!empty($input['nickName'])){

           $dis[] = ['b.nickName','like','%'.$input['nickName'].'%'];
       }

       $dis[] = ['a.active_id','=',$input['id']];
        //查询
       $data  = $this->model->AdminList($dis,$input['limit']);
       //活动名称
       $data['active_name'] = $this->active_model->where(['id'=>$input['id']])->value('title');

       return $this->success($data);
    }


    /**
     * @author chenniang
     * @DataTime: 2020-03-21 14:20
     * @功能说明:领券记录
     */
    public function logList(){

        $input = $this->_input;

        $dis[] = ['a.uniacid','=',$this->_uniacid];
        //查询指定活动
        $dis[] = ['a.active_id','=',$input['id']];
        //是否是员工
        if(isset($input['is_staff'])&&$input['is_staff']!=2){

            $dis[] = ['b.is_staff','=',$input['is_staff']];
        }

        $diss = [];
        //用户昵称 员工昵称
        if(!empty($input['name'])){
            //用户昵称
            $diss[] = ['b.nickName','like',"%".$input['name']."%"];
            //员工昵称
            $diss[] = ['c.name','like',"%".$input['name']."%"];
        }

        $data = $this->log_model->AdminList($dis,$diss,$input['limit']);

        $data['active_name'] = $this->active_model->where(['id'=>$input['id']])->value('title');

        return $this->success($data);

    }


    /**
     * @author chenniang
     * @DataTime: 2020-03-21 14:49
     * @功能说明:用户领券数据
     */
    public function userCouponList(){

        $input = $this->_input;

        $dis[] = ['a.uniacid','=',$this->_uniacid];

        $dis[] = ['a.share_user','=',$input['user_id']];

        $dis[] = ['a.active_id','=',$input['id']];
        //查询
        $data  = $this->model->AdminList($dis,$input['limit']);
        //用户昵称
        $data['user_name'] = $this->model->getUserName($input['user_id']);

        return $this->success($data);

    }







}
